package com.mycat.web.controller.ucenter.privates;

import com.mycat.common.entity.InvokeResult;
import com.mycat.dao.entity.ucenter.Customer;
import com.mycat.service.ucenter.CustomerService;
import com.mycat.web.common.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author roger.
 * @email luojie@yzworld.cn
 * @date 2016/10/27
 */
@RestController
@RequestMapping("/private/customer")
public class CustomerController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private CustomerService customerService;

    @RequestMapping(value = "/{id}",method= RequestMethod.GET)
    public ResponseEntity<InvokeResult<Customer>> getCustomer(@PathVariable("id") Integer id){
        InvokeResult invokeResult = null;
        try{
            Customer customer = customerService.findCustomer(id);
            if(null != customer){
                invokeResult = InvokeResult.success(customer);
            }else{
                invokeResult = InvokeResult.pass_no_data();
            }
        }catch (Exception e){
            logger.error(e.getMessage(), e);
            invokeResult = InvokeResult.error();
        }
        return new ResponseEntity(invokeResult, HttpStatus.valueOf(invokeResult.getCode()));
    }

}
